#ifndef _SETTINGS_H_
#define _SETTINGS_H_

#include "Include.h"
#include "DBInterface.h"


class Settings : public ACE_Task<ACE_MT_SYNCH>
{
private:
	static Settings * g_SettingValues;
	static ACE_Thread_Mutex setting_lock;
public:
	static Settings* GetSettings();
public:

	 std::string RENDERER_ID;


	 char SPEED[50];
	 char OBJECT_DIR[256];      	
	 char ADD_DIR[256];         	
	 char TMP_DIR[256];         	

	 char LOG_TYPE;
	 char LOG_LEVEL;

	 char SCALING_LOG_DIR[256];
	 char PROCESS_LOG_DIR[256]; 	
	 char JOB_LOG_DIR[256];     	

	 int HIGH_WIDTH;      	
	 int HIGH_HEIGHT;

	 int HIGH_WIDTH2;      	
	 int HIGH_HEIGHT2;     

	 int HIGH_BITRATE;
	 int HIGH_AUDIO_BITRATE;

	 int MIDDLE_WIDTH;    	
	 int MIDDLE_HEIGHT;   	

	 int MIDDLE_WIDTH2;    	
	 int MIDDLE_HEIGHT2;   	

	 int MIDDLE_BITRATE;
	 int MIDDLE_AUDIO_BITRATE;

	 int LOW_WIDTH;       	
	 int LOW_HEIGHT;  

	 int LOW_WIDTH2;       	
	 int LOW_HEIGHT2;  

	 int LOW_BITRATE;
	 int LOW_AUDIO_BITRATE;

	 char PRIMARY_CONTROLLER_ADDR[256];
	 char SECONDARY_CONTROLLER_ADDR[256];
	 int CONTROLLER_PORT;

	 char CMS_VERSION[100];
	 int CMS_PORT;  

	 int FRAME_RATE;
	 int IFRAME_INTERVAL;
	 int SAMPLING_RATE;

	 int MAX_IMAGE;     
	 int MAX_EFFECT;
	 double EFFECT_MIN_SIZE;
	 double EFFECT_MAX_SIZE;

	 int CONNECTION_CHECK_DELAY;	
	 int CONNECTION_CHECK_COUNT;	
	 int JOB_CHECK_DELAY;	
	 int SETTING_CHECK_COUNT;

	 int MAX_AGENT;
	 char RENDERER_LOG_MODE[20];

	 double RENDERER_CPU_MULTIPLE;
	 int RENDERER_THREAD_COUNT;

	 char OPERATION_MODE;

	 int SCALE_UP_INTERVAL;
	 int SCALE_DOWN_INTERVAL;
	 int RENDERING_PER_MIN;
	 int AGENT_BLOCK_SIZE;
	 double BLOCK_CALC_RATIO;


	 int MAX_PROCESS_TIME; 

	 int MAX_JOB_LIST;
	 int MIN_JOB_LIST;

	 double BGM_FADE_DURATION;
	 double SOUND_FADE_DURATION;

	 int MAX_MOVIE_TIME;

	 int S3_RETRY_COUNT;
	 int QUEUE_DELAY;

	 char PUSH_UUID[100];
	 char PUSH_SECRET_KEY[100];
	 char PUSH_INFO_GROUP_CODE[100];
	 char PUSH_ERROR_GROUP_CODE[100];
	 char PUSH_URL[100];
	 int PUSH_ALIVE_TICK_DELAY;

	 char ADD_TRAILER;
	 char  TRAILER_FILE_NAME[256];	
	 char  TRAILER_FILE_NAME2[256];	
	 double  TRAILER_TIME;
	 double  TRAILER_FADE_TIME;

	 char ADD_WATERMARK;
	 char WATERMARK_FILE_NAME[256];

	 int WATERMARK_HEIGHT_RATIO;	
	 int WATERMARK_MARGIN_RATIO;	
	 int WATERMARK_HEIGHT_RATIO2;	
	 int WATERMARK_MARGIN_RATIO2;	

	 int SEGMENT_TIME;
	
public:
	 double FRAME_INTERVAL;
	 char RENDERER_HEAD_CMD[1024];
	 std::string CONTROLLER_ADDR;
	 std::string LOCAL_ADDR;

	 std::string PRESET;

public:

	 static bool Start();
	 static void Release();

	 static Settings* Init();
	 static bool Change(Settings * new_values);

	 static bool ApplyChangedSettingValue();

	 static bool IsDebugMode();

	 std::string GetRendererTailCmd(int bv , int ba);



public:

	Settings(const std::string& renderer_id)
	{
		this->RENDERER_ID = renderer_id;
		this->LOCAL_ADDR = "";
	}

	 bool ReadFromDB();
	 void MatchDBValues(MYSQL_BIND * pArr);

	 void CalcValues();
	 void GetLocalAddr();

	 std::string dump();

#ifdef CONTROLLER
	bool IsPrimary();
#endif

	bool IsControllerAddr();
	std::string GetControllerAddr();


public:
	friend bool operator == ( Settings & s1,  Settings & s2)
	{	
		return s1.dump()  == s2.dump();
	}

	friend bool operator != ( Settings & s1,  Settings & s2)
	{	
		return s1.dump()  != s2.dump();
	}



};


#endif
